// components/stickyTop/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    scrollTop: {
      type: Number,
      value: 0,
      observer(newData, oldData) {
        this.getStickyOffsetTop()
      }
    },
    top: {
      type: [Number],
      value: 0
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    containerHeight: '',
    containerInfo: {}
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 获取当前容器的offsetTop
    getStickyOffsetTop() {
      wx.createSelectorQuery().in(this).select('.sticky-container').boundingClientRect(res => {
        // console.log(res);
        if (res.top < this.properties.top) {
          this.setData({
            containerHeight: res.height
          })
        }
        this.setData({
          containerInfo: res
        })
      }).exec()
    }
  }
})
